home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / OWLINC.PAK / SHELLITM.H < prev    next >
C/C++ Source or Header  |  1997-05-06  |  35KB  |  1,153 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1995, 1997 by Borland International, All Rights Reserved
  4. //
  5. //$Revision:   10.18  $
  6. //
  7. // Definitions of Win95 Shell Clases:
  8. //   TShellItem, TShellItemIterator, TPidl, TShellMalloc
  9. //
  10. // Also the following lightweight "wrapper" classes are defined:
  11. //   TExtractIcon, TContextMenu, TDataObject, TDropTarget
  12. //
  13. // These are wrapper classes for the Win95 deskop.
  14. //----------------------------------------------------------------------------
  15. #if !defined(OWL_SHELLITM_H)
  16. #define OWL_SHELLITM_H
  17.  
  18. #if !defined(OWL_EXCEPT_H)
  19. # include <owl/except.h>
  20. #endif
  21. #if !defined(OWL_DEFS_H)
  22. # include <owl/defs.h>
  23. #endif
  24. #if !defined(OCF_OLEUTIL_H)
  25. # include <ocf/oleutil.h>
  26. #endif
  27. #if !defined(WINSYS_STRING_H)
  28. # include <winsys/string.h>
  29. #endif
  30. #if !defined(_SHLOBJ_H_)
  31. # include <shlobj.h>
  32. #endif
  33.  
  34. #if defined(BI_NAMESPACE)
  35. namespace OWL {
  36. #endif
  37.  
  38. // Generic definitions/compiler options (eg. alignment) preceeding the
  39. // definition of classes
  40. #include <services/preclass.h>
  41.  
  42. //
  43. // class TShellMalloc
  44. // ~~~~~ ~~~~~~~~~~~~
  45. // wraps the shell's IMalloc interface
  46. // Default constructor obtains shell's IMalloc interface
  47. // TComRef<IMalloc> and copy constructors supplied
  48. // TComRef<IMalloc> and TShellMalloc assignment operators also supplied
  49. //
  50. //
  51. class TShellMalloc: public TComRef<IMalloc> {
  52.   public:
  53.     TShellMalloc();
  54.     TShellMalloc(const TComRef<IMalloc>& source);
  55.     TShellMalloc(const TShellMalloc& source);
  56.     TShellMalloc& operator = (const TComRef<IMalloc>& source);
  57.     TShellMalloc& operator = (const TShellMalloc& source);
  58. };
  59.  
  60. //
  61. // class TExtractIcon
  62. // ~~~~~ ~~~~~~~~~~~~
  63. // Wraps the IExtractIcon interface (currently lightweight)
  64. // A TExtractIcon is returned by TShellItem::GetExtractIcon
  65. // Default, TComRef<IExtractIcon> and copy constructors supplied
  66. // TComRef<IExtractIcon> and TExtractIcon assignment opreators also supplied
  67. //
  68. class TExtractIcon: public TComRef<IExtractIcon> {
  69.   public:
  70.     TExtractIcon(IExtractIcon* iface = 0);
  71.     TExtractIcon(const TComRef<IExtractIcon>& source);
  72.     TExtractIcon(const TExtractIcon& source);
  73.     TExtractIcon& operator= (const TComRef<IExtractIcon>& source);
  74.     TExtractIcon& operator= (const TExtractIcon& source);
  75. };
  76.  
  77. //
  78. // class TContextMenu
  79. // ~~~~~ ~~~~~~~~~~~~
  80. // Wraps the IContextMenu interface (currently lightweight)
  81. // A TContextMenu is returned by TShellItem::GetContextMenu
  82. // Default, TComRef<IContextMenu> and copy constructors supplied
  83. // TComRef<IContextMenu> and TContextMenu assignment opreators also supplied
  84. //
  85. class TContextMenu: public TComRef<IContextMenu> {
  86.   public:
  87.     TContextMenu(IContextMenu* iface = 0);
  88.     TContextMenu(const TComRef<IContextMenu>& source);
  89.     TContextMenu(const TContextMenu& source);
  90.     TContextMenu& operator = (const TComRef<IContextMenu>& source);
  91.     TContextMenu& operator = (const TContextMenu& source);
  92. };
  93.  
  94. //
  95. // class TDataObject
  96. // ~~~~~ ~~~~~~~~~~~
  97. // Wraps the IDataObject interface (currently lightweight)
  98. // A TDataObject is returned by TShellItem::GetDataObject
  99. // Default, TComRef<IDataObject> and copy constructors supplied
  100. // TComRef<IDataObject> and TDataObject assignment opreators also supplied
  101. //
  102. class TDataObject: public TComRef<IDataObject> {
  103.   public:
  104.     TDataObject(IDataObject* iface = 0);
  105.     TDataObject(const TComRef<IDataObject>& source);
  106.     TDataObject(const TDataObject& source);
  107.     TDataObject& operator = (const TComRef<IDataObject>& source);
  108.     TDataObject& operator = (const TDataObject& source);
  109. };
  110.  
  111. //
  112. // class TDropTarget
  113. // ~~~~~ ~~~~~~~~~~~
  114. // Wraps the IDropTarget interface (currently lightweight)
  115. // A TDropTarget is returned by TShellItem::GetDropTarget
  116. // Default, TComRef<IDropTarget> and copy constructors supplied
  117. // TComRef<IDropTarget> and TDropTarget assignment opreators also supplied
  118. //
  119. class TDropTarget: public TComRef<IDropTarget> {
  120.   public:
  121.     TDropTarget(IDropTarget* iface = 0);
  122.     TDropTarget(const TComRef<IDropTarget>& source);
  123.     TDropTarget(const TDropTarget& source);
  124.     TDropTarget& operator = (const TComRef<IDropTarget>& source);
  125.     TDropTarget& operator = (const TDropTarget& source);
  126. };
  127.  
  128. //
  129. // class TPidl
  130. // ~~~~~ ~~~~~
  131. // item identifier list class (ITEMIDLIST)
  132. // constructor takes an ITEMIDLIST* (a.k.a., pidl)
  133. // copy constructor and assignement operators supplied
  134. // functions to manipulate the ITEMIDLIST, get the size, get the number
  135. // of items in the list, etc, supplied
  136. // Normally, the programmer will not have to be concerned with ITEMIDLISTs
  137. // nor with the TPidl class.  The TShellItem class hides all this.
  138. //
  139. class TPidl {
  140.   public:
  141.     static ITEMIDLIST* Next(ITEMIDLIST *pidl);
  142.  
  143.     // TPidl constructors and destructor
  144.     //
  145.     TPidl(ITEMIDLIST* pidl = 0);
  146.     TPidl(const TPidl& source);
  147.     virtual ~TPidl();
  148.  
  149.     // Assignment operators
  150.     //
  151.     TPidl& operator = (const TPidl& source);
  152.     TPidl& operator = (ITEMIDLIST* pidl);
  153.  
  154.     // Test to see if valid pidl
  155.     operator !() const;
  156.  
  157.     // Use TPidl in place of pidl
  158.     operator const ITEMIDLIST* () const;
  159.  
  160.     // Use TPidl in place of pointer to a pidl (const)
  161.     //
  162.     operator const ITEMIDLIST ** () const;
  163.  
  164.     // Used to assign a new pidl
  165.     //
  166.     operator ITEMIDLIST** ();
  167.  
  168.     // Get size (in bytes) of a pidl
  169.     //
  170.     ulong GetSize() const;
  171.  
  172.     // Get number of item ids in the TPidl (the TPidl can be a list of ids)
  173.     //
  174.     long GetItemCount() const;
  175.  
  176.     // Get the last item id in the TPidl
  177.     //
  178.     TPidl GetLastItem() const;
  179.  
  180.     // Return a TPidl with the last item id stripped off of it
  181.     //
  182.     TPidl StripLastItem() const;
  183.  
  184.     // Copy a pidl
  185.     //
  186.     ITEMIDLIST* CopyPidl() const;
  187.  
  188.   protected:
  189.     // Free a pidl with the shell's allocator
  190.     //
  191.     void FreePidl();
  192.  
  193.   protected_data:
  194.  
  195.     // A PIDL
  196.     //
  197.     ITEMIDLIST* Pidl;
  198. };
  199.  
  200. //
  201. // class TShellItem
  202. // ~~~~~ ~~~~~~~~~~
  203. // An item in the shell's name space.  All items in the shell's
  204. // namespace can be identified by a fully qualified pidl.  Another
  205. // way to uniquely identify an item is via it's parent and an item id
  206. // (i.e., a single item rather than a list).  A TShellItem contains a
  207. // parent (TComRef<IShellFolder> ParentFolder) and the item id (TPidl pidl)
  208. //
  209. class TShellItem: public TComRef<IShellFolder> {
  210.   public:
  211.     // Used by TShelItem::GetDisplayName() and TShellItem::Rename()
  212.     // See MS doc for SHGNO for more information, Programmer's
  213.     // Guide to MS Windows 95, MS Press, p. 218.
  214.     //
  215.     enum TDisplayNameKind { 
  216.       Normal     = SHGDN_NORMAL,
  217.       InFolder   = SHGDN_INFOLDER,
  218.       ForParsing = SHGDN_FORPARSING
  219.     };
  220.     // Used by TShellItem::GetIcon
  221.     // See MS doc for SHGetFileInfo for more information, Programmer's
  222.     // Guide to MS Windows 95, MS Press, pp. 205-207.
  223.     enum TIconSize { Large    = SHGFI_LARGEICON,
  224.                      Small    = SHGFI_SMALLICON,
  225.                      Shell    = SHGFI_SHELLICONSIZE
  226.     };
  227.  
  228.     // Used by TShellItem::GetIcon
  229.     // See MS doc for SHGetFileInfo for more information, Programmer's
  230.     // Guide to MS Windows 95, MS Press, pp. 205-207.
  231.     //
  232.     enum TIconKind { 
  233.       Link     = SHGFI_LINKOVERLAY,
  234.       Open     = SHGFI_OPENICON,
  235.       Selected = SHGFI_SELECTED
  236.     };
  237.  
  238.     // Used by TShellItem::TShellItem(const TSpecialFolderKind kind,
  239.     //                                HWND windowOwner = 0)
  240.     // See MS doc for SHGetSpecialFolderLocation for more information,
  241.     // Programmer's Guide to MS Windows 95, MS Press, pp. 209-210.
  242.     //
  243.     enum TSpecialFolderKind { 
  244.       RecycleBin                  = CSIDL_BITBUCKET,
  245.       ControlPanel                = CSIDL_CONTROLS,
  246.       Desktop                     = CSIDL_DESKTOP,
  247.       DesktopFileDir              = CSIDL_DESKTOPDIRECTORY,
  248.       MyComputer                  = CSIDL_DRIVES,
  249.       Fonts                       = CSIDL_FONTS,
  250.       NetworkNeighborhoodFileDir  = CSIDL_NETHOOD,
  251.       NetworkNeighborhood         = CSIDL_NETWORK,
  252.       CommonDocuments             = CSIDL_PERSONAL,
  253.       Printers                    = CSIDL_PRINTERS,
  254.       Programs                    = CSIDL_PROGRAMS,
  255.       RecentDocuments             = CSIDL_RECENT,
  256.       SendTo                      = CSIDL_SENDTO,
  257.       StartMenu                   = CSIDL_STARTMENU,
  258.       Startup                     = CSIDL_STARTUP,
  259.       CommonTemplates             = CSIDL_TEMPLATES,
  260.       Favorites                   = CSIDL_FAVORITES
  261.     };
  262.  
  263.     // Used by TShellItem::GetAttributes
  264.     // See MS doc for IShellFolder::GetAttributesOf for more information,
  265.     // Programmer's Guide to MS Windows 95, MS Press, pp. 194-196.
  266.     //
  267.     enum TAttribute { 
  268.       // Capabilities
  269.       //
  270.       atCapabilityMask           = SFGAO_CAPABILITYMASK,
  271.       atCanBeCopied              = SFGAO_CANCOPY,
  272.       atCanBeDeleted             = SFGAO_CANDELETE,
  273.       atCanCreateShortcut        = SFGAO_CANLINK,
  274.       atCanBeMoved               = SFGAO_CANMOVE,
  275.       atCanBeRenamed             = SFGAO_CANRENAME,
  276.       atIsADropTarget            = SFGAO_DROPTARGET,
  277.       atHasAPropertySheet        = SFGAO_HASPROPSHEET,
  278.  
  279.       // Display Attributes
  280.       //
  281.       atDisplayAttributeMask     = SFGAO_DISPLAYATTRMASK,
  282.       atDisplayGhosted           = SFGAO_GHOSTED,
  283.       atIsShortcut               = SFGAO_LINK,
  284.       atIsReadOnly               = SFGAO_READONLY,
  285.       atIsShared                 = SFGAO_SHARE,
  286.  
  287.       // Contents
  288.       //
  289.       atContentsMask             = SFGAO_CONTENTSMASK,
  290.       atContainsSubFolder        = SFGAO_HASSUBFOLDER,
  291.  
  292.       // Miscellaneous
  293.       //
  294.       atContainsFileSystemFolder = SFGAO_FILESYSANCESTOR,
  295.       atIsPartOfFileSystem       = SFGAO_FILESYSTEM,
  296.       atIsFolder                 = SFGAO_FOLDER,
  297.       atCanBeRemoved             = SFGAO_REMOVABLE
  298.     };
  299.  
  300.     // Used by TShellItem::Rename,Copy,Move,Delete
  301.     // See MS doc for SHFILEOPSTRUCT for more information, Programmer's
  302.     // Guide to MS Windows 95, MS Press, pp. 214-215.
  303.     //
  304.     enum TFileOpFlags { 
  305.       AllowUndo         = FOF_ALLOWUNDO,
  306.       NoConfirmation    = FOF_NOCONFIRMATION,
  307.       NoConfirmMkDir    = FOF_NOCONFIRMMKDIR,
  308.       RenameOnCollision = FOF_RENAMEONCOLLISION,
  309.       Silent            = FOF_SILENT,
  310.       SimpleProgress    = FOF_SIMPLEPROGRESS
  311.     };
  312.  
  313.     // Used by TShellItem::BrowseForFolder
  314.     // See MS doc for BROWSEINFO for more information, Programmer's
  315.     // Guide to MS Windows 95, MS Press, pp. 211-212.
  316.     //
  317.     enum TBrowseFlags { 
  318.       OnlyComputers,
  319.       OnlyPrinters,
  320.       NoNetorkFoldersBelowDomain,
  321.       OnlyFSAncestors,
  322.       OnlyFSDirs
  323.     };
  324.  
  325.     // Returned by TShellItem::GetExeType
  326.     // See MS doc for SHGetFileInfo for more information, Programmer's
  327.     // Guide to MS Windows 95, MS Press, pp. 205-207.
  328.     //
  329.     enum TExeKind { 
  330.       NonExecutable,
  331.       WindowsNE,
  332.       WindowsPE,
  333.       MSDOS,
  334.       Win32Console
  335.     };
  336.  
  337.     // TCreateStruct contains information to construct a TShellItem
  338.     // Typically a TCreateStruct is returned (for example by GetParentFolder)
  339.     // and this TCreateStruct is used to construct a TshellItem
  340.     // Passed in as arguments to:
  341.     //    TShellItem::TShellItem(const TCreateStruct& cs)
  342.     //    TShellItem::operator =(const TCreateStruct& cs)
  343.     // Returned as an out argument by:
  344.     //    TShellItem::BrowseForFolder
  345.     //    TShellItem::ParseDisplayName
  346.     // Returned by:
  347.     //    TShellItem::GetParentFolder
  348.     //    TShellItemIterator::operator ++ ();
  349.     //    TShellItemIterator::operator ++ (int);
  350.     //    TShellItemIterator::operator -- ();
  351.     //    TShellItemIterator::operator -- (int);
  352.     //    TShellItemIterator::operator [] (const long index);
  353.     //    TShellItemIterator::Current();
  354.     //
  355.     struct TCreateStruct {
  356.       TCreateStruct();
  357.       TCreateStruct(TPidl& ptr, TComRef<IShellFolder>& parentFolder);
  358.       TCreateStruct(const TCreateStruct& source);
  359.  
  360.       TPidl                 Pidl;
  361.       TComRef<IShellFolder> ParentFolder;
  362.     };
  363.  
  364.     // Constructors for TShellItem
  365.     //
  366.     TShellItem(const char* path, bool throwOnInvalidPath = true, HWND windowOwner = 0);
  367.     TShellItem(const TSpecialFolderKind kind, HWND windowOwner = 0);
  368.     TShellItem(const TCreateStruct& cs);  // used with TShellItemIterator
  369.     TShellItem(const TPidl& Pidl, const TComRef<IShellFolder>& parentFolder);
  370.     TShellItem(ITEMIDLIST* pidl = 0,
  371.                const TComRef<IShellFolder>& parentFolder = 0);
  372.     TShellItem(const TShellItem& source);
  373.  
  374.     // Assignment operators
  375.     //
  376.     TShellItem& operator =(const TShellItem& source);
  377.     TShellItem& operator =(const TCreateStruct& cs);
  378.  
  379.     // Determine if TShellItem reprsents a valid item
  380.     //
  381.     bool Valid() const;
  382.  
  383.     // Allow TShellItems to be used in place of pidls
  384.     operator ITEMIDLIST*();
  385.  
  386.     // Get TExtractIcon, TContextMenu, TDataObject, TDropTarget for a TShellItem
  387.     TExtractIcon  GetExtractIcon(HWND windowOwner = 0);
  388.     TContextMenu  GetContextMenu(HWND windowOwner = 0);
  389.     TDataObject   GetDataObject(HWND windowOwner = 0);
  390.     TDropTarget   GetDropTarget(HWND windowOwner = 0);
  391.     HICON         GetIcon(TIconSize size = Shell, uint kind = 0);
  392.  
  393.     // Get Attributes of a TShellItem
  394.     // GetAttributes - Get Capabilities, Display, Contents, & Misc. Attributes with one call
  395.     //
  396.     ulong GetAttributes(const ulong reqAttrib, const bool validateCachedInfo = false) const;
  397.  
  398.     // Attributes - Capabilties
  399.     //
  400.     bool CanBeCopied(const bool validateCachedInfo = false) const;
  401.     bool CanBeDeleted(const bool validateCachedInfo = false) const;
  402.     bool CanCreateShortcut(const bool validateCachedInfo = false) const;
  403.     bool CanBeMoved(const bool validateCachedInfo = false) const;
  404.     bool CanBeRenamed(const bool validateCachedInfo = false) const;
  405.     bool IsADropTarget(const bool validateCachedInfo = false) const;
  406.     bool HasAPropertySheet(const bool validateCachedInfo = false)const;
  407.  
  408.     // Attributes - Display
  409.     //
  410.     bool DisplayGhosted(const bool validateCachedInfo = false) const;
  411.     bool IsShortcut(const bool validateCachedInfo = false) const;
  412.     bool IsReadOnly(const bool validateCachedInfo = false) const;
  413.     bool IsShared(const bool validateCachedInfo = false) const;
  414.  
  415.     // Attributes - Contents
  416.     //
  417.     bool ContainsSubFolder(const bool validateCachedInfo = false) const;
  418.  
  419.     // Attributes - Miscellaneous
  420.     //
  421.     bool ContainsFileSystemFolder(const bool validateCachedInfo = false) const;
  422.     bool IsPartOfFileSystem(const bool validateCachedInfo = false) const;
  423.     bool IsFolder(const bool validateCachedInfo = false) const;
  424.     bool CanBeRemoved(const bool validateCachedInfo = false) const;
  425.  
  426.     // Attributes - Additional (Not part of GetAttributes)
  427.     //
  428.     bool IsDesktop() const;
  429.  
  430.     // Get TPidl (relative to parent)
  431.     //
  432.     TPidl GetPidl() const;
  433.  
  434.     // Get fully qualified TPidl
  435.     //
  436.     TPidl GetFullyQualifiedPidl() const;
  437.  
  438.     // Get Parent Folder
  439.     //
  440.     TCreateStruct GetParentFolder() const;
  441.  
  442.     // Get type of executable file (may return NonExecutable)
  443.     //
  444.     TExeKind GetExeType(uint* major = 0, uint* minor = 0) const;
  445.  
  446.     // Get type of file (e.g., "Borland C++ Header File", "Notepad File")
  447.     //
  448.     TString GetTypeName() const;
  449.  
  450.     // Get Displayname (for a TShellItem that's part of the filesystem, this is the filename)
  451.     //
  452.     TString GetDisplayName(const TDisplayNameKind kind = Normal) const;
  453.  
  454.     // Get path (only call if the TShellItem is part of the file system (IsPartOfFileSystem == true)
  455.     //
  456.     TString GetPath() const;
  457.  
  458.     // File Opertations (Rename, Copy, Move, Delete)
  459.     //
  460.     void Rename(const char* newName, HWND windowOwner = 0,
  461.                 const TDisplayNameKind kind = Normal);
  462.     bool Copy(const char* dest, const bool destIsFolder = true,
  463.               const ushort flags = 0, const char* title = 0,
  464.               HWND windowOwner = 0) const;
  465.     bool Copy(const TShellItem& dest, const ushort flags = 0, const char* title = 0,
  466.               HWND windowOwner = 0) const;
  467.     bool Move(const char* destFolder, const ushort flags = 0,
  468.               const char* title = 0, HWND windowOwner = 0);
  469.     bool Move(const TShellItem& destFolder, const ushort flags = 0,
  470.               const char* title = 0, HWND windowOwner = 0);
  471.     bool Delete(const ushort flags = 0, const char* title = 0,
  472.                 HWND windowOwner = 0);
  473.  
  474.     // Add to recent docs (Win95 taskbar:Start:Documents)
  475.     //
  476.     void AddToRecentDocs() const;
  477.  
  478.     // Get the TShellItem that a shortcut points to
  479.     //
  480.     TShellItem ResolveShortcut(HWND windowOwner = 0);
  481.  
  482.     // Create a shortcut
  483.     //
  484.     static HRESULT CreateShortCut(LPCSTR objPath, LPSTR pathLink, 
  485.                                   LPSTR description);
  486.     static HRESULT CreateShortCut(LPCITEMIDLIST pidl, LPSTR pathLink,
  487.                                   LPSTR description);
  488.     TShellItem     CreateShortCut(LPSTR pathLink, LPSTR description);  
  489.  
  490.     // Pidl compares (so that they can be ordered)
  491.     //
  492.     bool operator==(const TShellItem& rhs) const;
  493.     bool operator!=(const TShellItem& rhs) const;
  494.     bool operator<(const TShellItem& rhs) const;
  495.     bool operator<=(const TShellItem& rhs) const;
  496.     bool operator>(const TShellItem& rhs) const;
  497.     bool operator>=(const TShellItem& rhs) const;
  498.  
  499.     // Folder Only Functions
  500.     // EnumObjects is called by TShellItemIterator
  501.     //
  502.     void EnumObjects(IEnumIDList** iface, HWND windowOwner = 0,
  503.                      const int kind = -1) const;
  504.     // Select a Foler under this TShellItem
  505.     //
  506.     bool BrowseForFolder(TCreateStruct& cs, HWND windowOwner = 0,
  507.                          const char* title = 0, const UINT flags = 0,
  508.                          int* image = 0, const bool includeStatus = false,
  509.                          BFFCALLBACK func = 0, const LPARAM param = 0) const;
  510.  
  511.     // Parse a display name into a TShellItem (actually, into a TCreateStruct)
  512.     //
  513.     HRESULT ParseDisplayName(TCreateStruct& cs, const char* displayName,
  514.                              ulong* eaten = 0, HWND windowOwner = 0,
  515.                              ulong* attrib = 0) const;
  516.   protected:
  517.     // CompareIDs is used by the pidl compare functions above
  518.     //
  519.     short CompareIDs(const TShellItem& rhs) const;
  520.     void  EnforceValidity() const;
  521.     void  RetrieveIShellFolder() const;
  522.     bool  HaveSameParent(const TShellItem& other) const;
  523.     bool  GetAttribute(const TAttribute at, const bool validateCachedInfo) const;
  524.   protected_data:
  525.     TPidl                 Pidl;
  526.     TComRef<IShellFolder> ParentFolder;
  527. };
  528.  
  529. //
  530. // class TShellItemIterator
  531. // ~~~~~ ~~~~~~~~~~~~~~~~~~
  532. //
  533. class TShellItemIterator: public TComRef<IEnumIDList> {
  534.   public:
  535.     // Used by TShellItemIterator::TShellItemIterator(const TShellItem& folder,
  536.     // HWND windowOwner = 0, const UINT kind = Folders | NonFolders)
  537.     // See MS doc for SHCONTF for more information, Programmer's Guide to
  538.     // MS Windows 95, MS Press, p. 213.
  539.     enum TIncludeKind { 
  540.       Folders         = SHCONTF_FOLDERS,
  541.       NonFolders      = SHCONTF_NONFOLDERS,
  542.       HiddenAndSystem = SHCONTF_INCLUDEHIDDEN
  543.     };
  544.  
  545.     // constructor for TShellItemIterator
  546.     //
  547.     TShellItemIterator(const TShellItem& folder, HWND windowOwner = 0,
  548.                        const int kind = Folders | NonFolders);
  549.     TShellItemIterator(const TShellItemIterator& source);
  550.  
  551.     // Assignment operator
  552.     //
  553.     TShellItemIterator& operator= (const TShellItemIterator& source);
  554.  
  555.     // True if iterator is still valid
  556.     //
  557.     bool Valid() const;
  558.  
  559.     // Get number of TShellItems in the list
  560.     //
  561.     long GetCount() const;
  562.  
  563.     // Get next item, previous item, item at index, and current item
  564.     //
  565.     TShellItem::TCreateStruct operator ++ ();
  566.     TShellItem::TCreateStruct operator ++ (int);
  567.     TShellItem::TCreateStruct operator -- ();
  568.     TShellItem::TCreateStruct operator -- (int);
  569.     TShellItem::TCreateStruct operator [] (const long index);
  570.     TShellItem::TCreateStruct Current();
  571.  
  572.     // Skip count items
  573.     //
  574.     void Skip(const ulong count);
  575.  
  576.     // Reset list
  577.     //
  578.     void Reset();
  579.  
  580.   protected:
  581.     void Next();
  582.     void EnforceValidInterface() const;
  583.  
  584.   protected_data:
  585.     long                  Index;
  586.     TPidl                 Pidl;
  587.     TComRef<IShellFolder> Folder;
  588.     operator IEnumIDList**();
  589. };
  590.  
  591. //
  592. // class TXShell
  593. // ~~~~~ ~~~~~~~
  594. // Base Shell exception class. Handles all TShellItem and related class exceptions
  595. //
  596. class _OWLCLASS_RTL TXShell: public TXOwl {
  597.   public:
  598.     // Constructor for TXShell
  599.     //
  600.     TXShell(uint resId = IDS_SHELLFAILURE, HANDLE handle = 0);
  601.  
  602.     // Clone a TXShell
  603.     //
  604. #if defined(BI_NO_COVAR_RET)
  605.     TXBase* Clone();
  606. #else
  607.     TXShell* Clone();
  608. #endif
  609.     // Throw an exception
  610.     //
  611.     void Throw();
  612.  
  613.     // Construct a TXShell exception from scratch, and throw it.
  614.     //
  615.     static void Raise(uint resId = IDS_SHELLFAILURE, HANDLE handle = 0);
  616.  
  617.     // Check an HRESULT and throw a TXShell if not SUCCEEDED(hr)
  618.     //
  619.     static void Check(HRESULT hr, uint resId = IDS_SHELLFAILURE, HANDLE handle = 0);
  620. };
  621.  
  622. // Generic definitions/compiler options (eg. alignment) following the
  623. // definition of classes
  624. #include <services/posclass.h>
  625.  
  626. #if defined(BI_NAMESPACE)
  627. } // namespace OWL
  628. #endif
  629.  
  630. //----------------------------------------------------------------------------
  631. // Inline implementations
  632. //
  633.  
  634. // Default constructor for TShellMalloc.  For more info, see MS doc for
  635. //   SHGetMalloc (Prog. Guide to MS Win95, p. 208)
  636. //
  637. inline TShellMalloc::TShellMalloc()
  638. {
  639.   HRESULT hr = ::SHGetMalloc(*this);
  640.   TXShell::Check(hr, IDS_SHGETMALLOCFAIL);
  641. }
  642.  
  643. // TShellMalloc constructor to construct from TComRef<IMalloc>
  644. //
  645. inline TShellMalloc::TShellMalloc(const TComRef<IMalloc>& source)
  646.                     :TComRef<IMalloc>(source)
  647. {
  648. }
  649.  
  650. // TShellMalloc copy constructor
  651. //
  652. inline TShellMalloc::TShellMalloc(const TShellMalloc& source)
  653.                     :TComRef<IMalloc>(source)
  654. {
  655. }
  656.  
  657. // TShellMalloc assignment operator (from TComRef<IMalloc>)
  658. //
  659. inline TShellMalloc& 
  660. TShellMalloc::operator =(const TComRef<IMalloc>& source)
  661. {
  662.   if (&source != this)
  663.     TComRef<IMalloc>::operator=(source);
  664.   return *this;
  665. }
  666.  
  667. // TShellMalloc assignment operator (from another TShellMalloc)
  668. //
  669. inline TShellMalloc& 
  670. TShellMalloc::operator =(const TShellMalloc& source)
  671. {
  672.   if (&source != this)
  673.     TComRef<IMalloc>::operator=(source);
  674.   return *this;
  675. }
  676.  
  677. // Default constructor for TExtractIcon
  678. //
  679. inline TExtractIcon::TExtractIcon(IExtractIcon* iface)
  680.                     :TComRef<IExtractIcon>(iface)
  681. {
  682. }
  683.  
  684. // TExtractIcon constructor to construct from TComRef<IExtractIcon>
  685. //
  686. inline TExtractIcon::TExtractIcon(const TComRef<IExtractIcon>& source)
  687.                     :TComRef<IExtractIcon>(source)
  688. {
  689. }
  690.  
  691. // TExtractIcon copy constructor
  692. //
  693. inline TExtractIcon::TExtractIcon(const TExtractIcon& source)
  694.                     :TComRef<IExtractIcon>(source)
  695. {
  696. }
  697.  
  698. // TExtractIcon assignment operator (from TComRef<IExtractIcon>)
  699. //
  700. inline TExtractIcon& 
  701. TExtractIcon::operator =(const TComRef<IExtractIcon>& source)
  702. {
  703.   if (&source != this)
  704.     TComRef<IExtractIcon>::operator=(source);
  705.   return *this;
  706. }
  707.  
  708. // TExtractIcon assignment operator (from another TExtractIcon)
  709. //
  710. inline TExtractIcon& 
  711. TExtractIcon::operator =(const TExtractIcon& source)
  712. {
  713.   if (&source != this)
  714.     TComRef<IExtractIcon>::operator=(source);
  715.   return *this;
  716. }
  717.  
  718. // Default constructor for TContextMenu
  719. //
  720. inline TContextMenu::TContextMenu(IContextMenu* iface)
  721.                     :TComRef<IContextMenu>(iface)
  722. {
  723. }
  724.  
  725. // TContextMenu constructor to construct from TComRef<IContextMenu>
  726. //
  727. inline TContextMenu::TContextMenu(const TComRef<IContextMenu>& source)
  728.                     :TComRef<IContextMenu>(source)
  729. {
  730. }
  731.  
  732. // TContextMenu copy constructor
  733. //
  734. inline TContextMenu::TContextMenu(const TContextMenu& source)
  735.                     :TComRef<IContextMenu>(source)
  736. {
  737. }
  738.  
  739. // TContextMenu assignment operator (from TComRef<IContextMenu>)
  740. //
  741. inline TContextMenu& 
  742. TContextMenu::operator =(const TComRef<IContextMenu>& source)
  743. {
  744.   if (&source != this)
  745.     TComRef<IContextMenu>::operator=(source);
  746.   return *this;
  747. }
  748.  
  749. // TContextMenu assignment operator (from another TContextMenu)
  750. //
  751. inline TContextMenu& 
  752. TContextMenu::operator = (const TContextMenu& source)
  753. {
  754.   if (&source != this)
  755.     TComRef<IContextMenu>::operator=(source);
  756.   return *this;
  757. }
  758.  
  759. // Default constructor for TDataObject
  760. //
  761. inline TDataObject::TDataObject(IDataObject* iface)
  762. :
  763.   TComRef<IDataObject>(iface)
  764. {
  765. }
  766.  
  767. // TDataObject constructor to construct from TComRef<IDataObject>
  768. //
  769. inline TDataObject::TDataObject(const TComRef<IDataObject>& source)
  770.                    :TComRef<IDataObject>(source)
  771. {
  772. }
  773.  
  774. // TDataObject copy constructor
  775. //
  776. inline TDataObject::TDataObject(const TDataObject& source)
  777.                    :TComRef<IDataObject>(source)
  778. {
  779. }
  780.  
  781. // TDataObject assignment operator (from TComRef<IDataObject>)
  782. //
  783. inline TDataObject& 
  784. TDataObject::operator =(const TComRef<IDataObject>& source)
  785. {
  786.   if (&source != this)
  787.     TComRef<IDataObject>::operator=(source);
  788.   return *this;
  789. }
  790.  
  791. // TDataObject assignment operator (from another TDataObject)
  792. //
  793. inline TDataObject& 
  794. TDataObject::operator =(const TDataObject& source)
  795. {
  796.   if (&source != this)
  797.     TComRef<IDataObject>::operator=(source);
  798.   return *this;
  799. }
  800.  
  801. // Default constructor for TDropTarget
  802. //
  803. inline TDropTarget::TDropTarget(IDropTarget* iface)
  804.                    :TComRef<IDropTarget>(iface)
  805. {
  806. }
  807.  
  808. // TDropTarget constructor to construct from TComRef<IDropTarget>
  809. //
  810. inline TDropTarget::TDropTarget(const TComRef<IDropTarget>& source)
  811.                    :TComRef<IDropTarget>(source)
  812. {
  813. }
  814.  
  815. // TDropTarget copy constructor
  816. //
  817. inline TDropTarget::TDropTarget(const TDropTarget& source)
  818.                    :TComRef<IDropTarget>(source)
  819. {
  820. }
  821.  
  822. // TDropTarget assignment operator (from TComRef<IDropTarget>)
  823. //
  824. inline TDropTarget& 
  825. TDropTarget::operator =(const TComRef<IDropTarget>& source)
  826. {
  827.   if (&source != this)
  828.     TComRef<IDropTarget>::operator=(source);
  829.   return *this;
  830. }
  831.  
  832. // TDropTarget assignment operator (from another TDropTarget)
  833. //
  834. inline TDropTarget& 
  835. TDropTarget::operator =(const TDropTarget& source)
  836. {
  837.   if (&source != this)
  838.     TComRef<IDropTarget>::operator=(source);
  839.   return *this;
  840. }
  841.  
  842. // Check to see if TPidl represents an ITEMIDLIST (return true if it does not)
  843. //
  844. inline TPidl::operator !() const
  845. {
  846.   return Pidl == 0;
  847. }
  848.  
  849. // Return next item id (in the list)
  850. //
  851. inline ITEMIDLIST* 
  852. TPidl::Next(ITEMIDLIST* pidl)
  853. {
  854.   return REINTERPRET_CAST(ITEMIDLIST*, REINTERPRET_CAST(char*, pidl) + pidl->mkid.cb);
  855. }
  856.  
  857. // TPidl copy constructor
  858. //
  859. inline TPidl::TPidl(const TPidl& source)
  860.              :Pidl(source.CopyPidl())
  861. {
  862. }
  863.  
  864. // Construct a TPidl from an ITEMIDLIST* (pidl)
  865. //
  866. inline TPidl::TPidl(ITEMIDLIST* pidl)
  867.              :Pidl(pidl)
  868. {
  869. }
  870.  
  871. // TPidl assignement operator (from another TPidl)
  872. //
  873. inline TPidl& 
  874. TPidl::operator =(const TPidl& source)
  875. {
  876.   if (&source == this)
  877.     return *this;
  878.   Pidl = source.CopyPidl();
  879.   return *this;
  880. }
  881.  
  882. // TPidl assignement operator (from an ITEMIDLIST* (pidl))
  883. //
  884. inline TPidl& 
  885. TPidl::operator =(ITEMIDLIST* pidl)
  886. {
  887.   FreePidl();
  888.   Pidl = pidl;
  889.   return *this;
  890. }
  891.  
  892. // TPidl destructor
  893. //
  894. inline TPidl::~TPidl()
  895. {
  896.   FreePidl();
  897. }
  898.  
  899. // use TPidl in place of ITEMIDLIST* (pidl)
  900. //
  901. inline TPidl::operator const ITEMIDLIST*() const
  902. {
  903.   return Pidl;
  904. }
  905.  
  906. // use TPidl in place of const ITEMIDLIST** (pointer to pidl) (const)
  907. //
  908. inline TPidl::operator const ITEMIDLIST **() const
  909. {
  910.   return CONST_CAST(const ITEMIDLIST**, &Pidl);
  911. }
  912.  
  913. // Used to set the ITEMIDLIST*
  914. //
  915. inline TPidl::operator ITEMIDLIST**()
  916. {
  917.   if (Pidl)
  918.     FreePidl();
  919.   return &Pidl;
  920. }
  921.  
  922. // Return true if the TShellItem represents an item in the namespace
  923. //
  924. inline bool TShellItem::Valid() const
  925. {
  926.   return !!Pidl && !!ParentFolder;
  927. }
  928.  
  929. // Attributes - Capabilties
  930.  
  931. // Return true if the TShellItem represents an item that can be copied
  932. //
  933. inline bool TShellItem::CanBeCopied(const bool validateCachedInfo) const
  934. {
  935.   return GetAttribute(atCanBeCopied, validateCachedInfo);
  936. }
  937.  
  938. // Return true if the TShellItem represents an item that can be deleted
  939. //
  940. inline bool TShellItem::CanBeDeleted(const bool validateCachedInfo) const
  941. {
  942.   return GetAttribute(atCanBeDeleted, validateCachedInfo);
  943. }
  944.  
  945. // Return true if the TShellItem represents an item for which a shortcut can
  946. // be created
  947. //
  948. inline bool TShellItem::CanCreateShortcut(const bool validateCachedInfo) const
  949. {
  950.   return GetAttribute(atCanCreateShortcut, validateCachedInfo);
  951. }
  952.  
  953. // Return true if the TShellItem represents an item that can be moved
  954. //
  955. inline bool TShellItem::CanBeMoved(const bool validateCachedInfo) const
  956. {
  957.   return GetAttribute(atCanBeMoved, validateCachedInfo);
  958. }
  959.  
  960. // Return true if the TShellItem represents an item that can be renamed
  961. //
  962. inline bool TShellItem::CanBeRenamed(const bool validateCachedInfo) const
  963. {
  964.   return GetAttribute(atCanBeRenamed, validateCachedInfo);
  965. }
  966.  
  967. // Return true if the TShellItem represents an item is a drop target
  968. //
  969. inline bool TShellItem::IsADropTarget(const bool validateCachedInfo) const
  970. {
  971.   return GetAttribute(atIsADropTarget, validateCachedInfo);
  972. }
  973.  
  974. // Return true if the TShellItem represents an item that has a property sheet
  975. //
  976. inline bool TShellItem::HasAPropertySheet(const bool validateCachedInfo) const
  977. {
  978.   return GetAttribute(atHasAPropertySheet, validateCachedInfo);
  979. }
  980.  
  981. // Attributes - Display
  982.  
  983. // Return true if the TShellItem represents an item that should be displayed
  984. // as ghosted
  985. //
  986. inline bool TShellItem::DisplayGhosted(const bool validateCachedInfo) const
  987. {
  988.   return GetAttribute(atDisplayGhosted, validateCachedInfo);
  989. }
  990.  
  991. // Return true if the TShellItem represents an item that is a shortcut
  992. //
  993. inline bool TShellItem::IsShortcut(const bool validateCachedInfo) const
  994. {
  995.   return GetAttribute(atIsShortcut, validateCachedInfo);
  996. }
  997.  
  998. // Return true if the TShellItem represents an item that is read only
  999. //
  1000. inline bool TShellItem::IsReadOnly(const bool validateCachedInfo) const
  1001. {
  1002.   return GetAttribute(atIsReadOnly, validateCachedInfo);
  1003. }
  1004.  
  1005. // Return true if the TShellItem represents an item that is shared
  1006. //
  1007. inline bool TShellItem::IsShared(const bool validateCachedInfo) const
  1008. {
  1009.   return GetAttribute(atIsShared, validateCachedInfo);
  1010. }
  1011.  
  1012. // Attributes - Contents
  1013.  
  1014. // Return true if the TShellItem represents an item that contains a subfolder
  1015. //
  1016. inline bool TShellItem::ContainsSubFolder(const bool validateCachedInfo) const
  1017. {
  1018.   return GetAttribute(atContainsSubFolder, validateCachedInfo);
  1019. }
  1020.  
  1021. // Attributes - Miscellaneous
  1022.  
  1023. // Return true if the TShellItem represents an item that contains a file system folder
  1024. //
  1025. inline bool TShellItem::ContainsFileSystemFolder(const bool validateCachedInfo) const
  1026. {
  1027.   return GetAttribute(atContainsFileSystemFolder, validateCachedInfo);
  1028. }
  1029.  
  1030. // Return true if the TShellItem represents an item that is part of the file system
  1031. //
  1032. inline bool TShellItem::IsPartOfFileSystem(const bool validateCachedInfo) const
  1033. {
  1034.   return GetAttribute(atIsPartOfFileSystem, validateCachedInfo);
  1035. }
  1036.  
  1037. // Return true if the TShellItem represents an item that is a folder
  1038. //
  1039. inline bool TShellItem::IsFolder(const bool validateCachedInfo) const
  1040. {
  1041.   return GetAttribute(atIsFolder, validateCachedInfo);
  1042. }
  1043.  
  1044. // Return true if the TShellItem represents an item that can be removed
  1045. //
  1046. inline bool TShellItem::CanBeRemoved(const bool validateCachedInfo) const
  1047. {
  1048.   return GetAttribute(atCanBeRemoved, validateCachedInfo);
  1049. }
  1050.  
  1051. // TShellItem::TCreateStruct default constructor
  1052. //
  1053. inline TShellItem::TCreateStruct::TCreateStruct()
  1054. {
  1055. }
  1056.  
  1057. // TShellItem::TCreateStruct constructor (takes a TPidl and TComRef<IShellFolder>
  1058. //
  1059. inline TShellItem::TCreateStruct::TCreateStruct(
  1060.                             TPidl& pidl, TComRef<IShellFolder>& parentFolder)
  1061. :
  1062.   Pidl(pidl),
  1063.   ParentFolder(parentFolder)
  1064. {
  1065. }
  1066.  
  1067. // TShellItem::TCreateStruct copy constructor
  1068. //
  1069. inline TShellItem::TCreateStruct::TCreateStruct(const TCreateStruct& source)
  1070. :
  1071. Pidl(source.Pidl),
  1072. ParentFolder(source.ParentFolder)
  1073. {
  1074. }
  1075.  
  1076. // use TShellItem in place of an ITEMIDLIST* (pidl)
  1077. //
  1078. inline TShellItem::operator ITEMIDLIST*()
  1079. {
  1080.   return Pidl;
  1081. }
  1082.  
  1083. // Get a TShellItem's TPidl
  1084. //
  1085. inline TPidl TShellItem::GetPidl() const
  1086. {
  1087.   return Pidl;  // Return a copy
  1088. }
  1089.  
  1090. // Compare sort order of this TShellItem equals another TShellItem
  1091. //
  1092. inline bool TShellItem::operator ==(const TShellItem& rhs) const
  1093. {
  1094.   return CompareIDs(rhs) == 0;
  1095. }
  1096.  
  1097. // Compare sort order of this TShellItem is less than another TShellItem
  1098. //
  1099. inline bool TShellItem::operator <(const TShellItem& rhs) const
  1100. {
  1101.   return CompareIDs(rhs) < 0;
  1102. }
  1103.  
  1104. // Compare sort order of this TShellItem is greater than another TShellItem
  1105. //
  1106. inline bool TShellItem::operator >(const TShellItem& rhs) const
  1107. {
  1108.   return CompareIDs(rhs) > 0;
  1109. }
  1110.  
  1111. // Compare sort order of this TShellItem is not equal to another TShellItem
  1112. //
  1113. inline bool TShellItem::operator !=(const TShellItem& rhs) const
  1114. {
  1115.   return !operator==(rhs);
  1116. }
  1117.  
  1118. // Compare sort order of this TShellItem <= another TShellItem
  1119. //
  1120. inline bool TShellItem::operator <=(const TShellItem& rhs) const
  1121. {
  1122.   return !operator>(rhs);
  1123. }
  1124.  
  1125. // Compare sort order of this TShellItem >= another TShellItem
  1126. //
  1127. inline bool TShellItem::operator >=(const TShellItem& rhs) const
  1128. {
  1129.   return !operator<(rhs);
  1130. }
  1131.  
  1132. // HaveSameParent returns true if this TShellItem and other TShellItem have the
  1133. // same immediate parent folder.
  1134. //
  1135. inline bool TShellItem::HaveSameParent(const TShellItem& other) const
  1136. {
  1137.   TShellItem* constThis = CONST_CAST(TShellItem*, this);
  1138.   TShellItem* constOther = CONST_CAST(TShellItem*, &other);
  1139.  
  1140.   return STATIC_CAST(IShellFolder*, constThis->ParentFolder) !=
  1141.          STATIC_CAST(IShellFolder*, constOther->ParentFolder);
  1142. }
  1143.  
  1144. // Return true if TShellItemIterator is valid and not at end of list of items
  1145. //
  1146. inline bool TShellItemIterator::Valid() const
  1147. {
  1148.   return Index != -1;
  1149. }
  1150.  
  1151. #endif  // OWL_SHELLITM_H
  1152.  
  1153.